package com.anyikang.volunteer.sos.volunteer.app.main;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.anyikang.volunteer.sos.volunteer.R;
import com.anyikang.volunteer.sos.volunteer.app.MyApplication;
import com.nostra13.universalimageloader.core.ImageLoader;


/**
 * A simple {@link Fragment} subclass.
 *
 */
public class BannerItemFragmentDemo extends Fragment implements OnClickListener {

	private int mItemId;
	private ImageView mImageView;
	private String mImgUrl;
	private String TAG="BannerItemFragmentDemo";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle b = this.getArguments();
		if(b != null)
		{
			mItemId = b.getInt("itemId");
			mImgUrl = b.getString("imgUrl");
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		View inflate = inflater.inflate(R.layout.fragment_banner_item,
				container, false);
		mImageView = (ImageView) inflate.findViewById(R.id.imageView1);
		if(mImgUrl == null)
		Log.i(TAG,"mImgUrl=null");
		else
			Log.i(TAG,mImgUrl);
		ImageLoader.getInstance().displayImage(mImgUrl,mImageView, MyApplication.options);

		inflate.setOnClickListener(this);
		return inflate;
	}


	public static BannerItemFragmentDemo newInstance(String imgUrl, int itemId) {
		BannerItemFragmentDemo fragment = new BannerItemFragmentDemo();
		Bundle args = new Bundle();
		args.putString("imgUrl", imgUrl);
		args.putInt("itemId", itemId);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void onClick(View v) {
		Toast.makeText(getActivity(),"敬请期待",Toast.LENGTH_SHORT).show();
	}

	public void setGoodsInfo(int itemId) {
		this.mItemId = itemId;
	}

}
